package com.qf.web;

import com.github.pagehelper.PageInfo;
import com.qf.bean.Training;
import com.qf.service.FanKuiService;
import com.qf.service.TrainingService;
import com.qf.utils.filter.enuml.FuHeEnum;
import com.qf.utils.filter.enuml.PageEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

/**
 * IntelliJ IDEA -> person
 * 2019/11/28 8:42
 *
 * @author zmyao
 * 别看，我是渣渣。
 */
@Controller
public class FankuiContrroller {
    @Autowired
    private FanKuiService fanKuiService;
    @Autowired
    private TrainingService trainingService;
    @RequestMapping("/peixun/peixunfankui/findAllFanKui")
    public String findAllFanKui(@RequestParam(defaultValue = "1") int index, String trainingname, String  trainingdateStart, String  trainingdateEnd, ModelMap map){
        PageInfo<Training> pageInfo = fanKuiService.findAllByOpintion(index, PageEnum.PAGESIZE.getSize(), trainingname, trainingdateStart, trainingdateEnd, FuHeEnum.PASS.getAuditopinion());
        map.addAttribute("pageInfo",pageInfo);
        map.addAttribute("trainingname",trainingname);
        map.addAttribute("trainingdateStart",trainingdateStart);
        map.addAttribute("trainingdateEnd",trainingdateEnd);
        return  "/peixun/peixunfankui/list";
    }
    @RequestMapping("/peixun/peixunfankui/fankui")
    public  String fankui(ModelMap map,Integer id ,String method){
        List<String> feedback = findTrainingFeedback();
        map.addAttribute("feedback",feedback);
        Training training = trainingService.selectByPrimaryKey(id);
        map.addAttribute("training",training);
        if ("jihuafankui".equals(method)){
            return  "/peixun/peixunfankui/fankui";
        }
        else {
            return  "/peixun/peixunjihua/fankui";
        }
    }

    @RequestMapping("/peixun/peixunfankui/updatefeedback")
    public String updatefeedback(String trainingfeedback,String trainingsummary,String trainingresult ,int id){
        int len = trainingService.updatefeedback(trainingfeedback, trainingsummary, trainingresult,id);
        if (len > 0){
            return  "redirect:/peixun/peixunfankui/findAllFanKui";
        }
        else {
            return "redirect:/peixun/peixunfankui/fankui?id=" + id + "";
        }
    }
    private List<String>   findTrainingFeedback(){
        return   trainingService.findTrainingFeedback();
    }

}
